//Defines the list of JAR libraries that we will use in this program.
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
//import org.junit.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

// Main java class. Everything will be inside here
public class YTSearchSignin {
	private WebDriver driver;
	private String baseUrl;
	private StringBuffer verificationErrors = new StringBuffer();
	@Before
	public void setUp() throws Exception {
		System.out.println("Hello this is @Before every @Test");
		driver = new FirefoxDriver(); // Driver object that points to a specific browser
		baseUrl = "http://www.youtube.com/";
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}

	@Test
	public void testYTSearchSignin() throws Exception {
		System.out.println("Hello this is @Test1");
		driver.get(baseUrl + "/");
		driver.findElement(By.id("masthead-search-term")).clear();
		driver.findElement(By.id("masthead-search-term")).sendKeys("QTP");
		driver.findElement(By.id("search-btn")).click();
		// ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
		driver.findElement(By.linkText("Movies")).click();
		driver.findElement(By.linkText("Upload")).click();
		driver.findElement(By.xpath("//input[@id='Email']")).clear();
		driver.findElement(By.xpath("//input[@id='Email']")).sendKeys("sdfsdfsdfsd");
		driver.findElement(By.xpath("//input[@name='Passwd']")).clear();
		driver.findElement(By.xpath("//input[@name='Passwd']")).sendKeys("sdfsdfsdfsdf");
		driver.findElement(By.xpath("//input[@type='submit']")).click();
	}

	@After
	public void tearDown() throws Exception {
		System.out.println("Hello this is @After every @Test");
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}
